/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.slimserver.musicjukebox.ui.components;

import com.bff.bjj.utils.Resources;
import com.bff.slimserver.music.MusicObjects;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import org.bff.slimserver.musicobjects.SlimArtist;

/**
 *
 * @author bfindeisen
 */
public class ArtistComboBox extends JComboBox {

    private DefaultComboBoxModel artistModel;

    public ArtistComboBox() {
        artistModel = new DefaultComboBoxModel();
       listArtists();
    }

    private void listArtists() {
        artistModel.removeAllElements();
        try {
            artistModel.addElement(Resources.getMessage(Resources.LABEL_KEY.ARTIST_ALL));
            List<SlimArtist>artistList = new ArrayList<SlimArtist>(MusicObjects.getArtists());
            for (SlimArtist artist : artistList) {
                artistModel.addElement(artist);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        setModel(artistModel);
    }
    
    public SlimArtist getSelectedArtist() {
        if(getSelectedIndex() == 0) {
            return null;
        }
        
        return (SlimArtist) getModel().getSelectedItem();
    }
}
